package homeWork;

import java.util.Scanner;

public class homeWork11 {
    public static void main(String[] args) {
        System.out.println("请输入一个整数：");
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int sum = sum(n);
        System.out.println("加到你输入的整数的和为：" + sum);
    }
    //递归求 1 + 2 + 3 + ... + n
    public static int sum (int n){
        if (n == 1){
            return 1;
        }else{
            return n + sum(n-1);
        }
    }
}
